using UnityEngine;
using System.Collections;

// to be attached to a visual planet's name board
public class NameOrbit : MonoBehaviour {

	public Transform target;
	public float factor = 0.05f;
	public Planet planet;

	public GUIText pText;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update ()
	{
		// offset = factor * (4 - size)
		// size = (scale - 0.5) / 0.15
		// refer to VisualMisc.cs, "orb =" calculation
		float offset = factor * (4 - (target.localScale.x - 0.5f) / 0.15f);
		Vector3 pos = new Vector3(target.transform.position.x,
			target.transform.position.y - offset, target.transform.position.z);
			
		transform.position = Camera.main.WorldToViewportPoint(pos + Vector3.up);
	}

	void LateUpdate()
	{
		if (null != planet && planet.Solar == Core.solarOnShow)
		{
			if (planet.Kingdom != null && planet.Kingdom.Race.RaceType > Galaxy.RaceType.None)
			{
				pText.material.color = planet.Kingdom.Race.RaceColor;
				pText.text = planet.PlanetName + " : " + planet.Kingdom.Race.RaceType.ToString();
			}
			else
			{
				pText.material.color = Color.white;
				pText.text = planet.PlanetName;
			}
		}
	}
}
